const api = require("../../utils/api")
const getwxphone = require("../../utils/getwxphone")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    z: 1
  },
  back() {
    this.setData({
      z: 1,
      gx: !1,
      yh: !1
    })
  },
  tosf() {

    wx.navigateToMiniProgram({
      appId: 'wx58c52a1b32912237',
      path: 'pages/sfs/sfs?data={"zwcode":"gj","zwyear":"2023","area":"","scode":""}',
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },
  gosearch() {
    var that = this;

    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/updateuser?actid=52237', //接收url
      data: {
        name: that.data.inputValue,
        zkz: that.data.inputValueT,
        phone:wx.getStorageSync('52237phone')
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)

      }
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getfzinfo?actid=52237', //接收url
      data: {
        name: that.data.inputValue,
        zkz: that.data.inputValueT,
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        if (theJson.status == 1) {
          that.setData({
            lists: theJson.lists,
            z: !1,
            gx: 1,
            yh: !1
          })
        } else {
          that.setData({
            lists: theJson.lists,
            z: !1,
            gx: !1,
            yh: 1
          })
        }
      }
    })
  },
  bindKeyInput: function (e) {
    var _ = this
    _.setData({
      inputValue: e.detail.value
    })
    console.log(_.data.inputValue)
  },
  bindKeyInputT: function (e) {
    var _ = this
    _.setData({
      inputValueT: e.detail.value
    })
    console.log(_.data.inputValueT)
  },
  getPhoneNumber(e) {
    var _ = this;
    const info = {
      area: wx.getStorageSync('area'),
      agent: wx.getStorageSync('agent'),
      page: wx.getStorageSync('page'),
      activeId: 36
    }

    getwxphone(e.detail.code, 52237, 'chaxun', info)
      .then(res => {
        console.log(res);
        this.gosearch()

      })
      .catch(err => {
        console.log(err);
      })
  },

  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../agreement/agreement',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    api.load(options)
    // 在页面中定义插屏广告
    // let interstitialAd = null

    // // 在页面onLoad回调事件中创建插屏广告实例
    // if (wx.createInterstitialAd) {
    //   interstitialAd = wx.createInterstitialAd({
    //     adUnitId: 'adunit-6a38c1b248bbba9b'
    //   })
    //   interstitialAd.onLoad(() => {})
    //   interstitialAd.onError((err) => {})
    //   interstitialAd.onClose(() => {})
    // }

    // // 在适合的场景显示插屏广告
    // if (interstitialAd) {
    //   interstitialAd.show().catch((err) => {
    //     console.error(err)
    //   })
    // }
    let phone = wx.getStorageSync('52237phone')
    if (phone) {
      this.setData({
        ifphone: 1
      })
    } else {
      this.setData({
        ifphone: !1
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})